﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Contracts.Interface.EliminationModelService;
using IntelligentAgriculture.Services;
using IntelligentAgriculture.WebAPI.Application.Command.DeathModelCommand;
using IntelligentAgriculture.WebAPI.Application.Command.EliminationModelCommand;
using MediatR;
using System.ComponentModel.Design;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.EliminationModelCommandHandler
{
    public class EliminationAddCommandHandler : IRequestHandler<EliminationAddCommand, Results<int>>
    {
        private readonly IEliminationModelService _IeliminationModelService;
        public EliminationAddCommandHandler(IEliminationModelService ieliminationModelService)
        {
            _IeliminationModelService = ieliminationModelService;
        }

        /// <summary>
        /// 添加死亡信息功能
        /// </summary>
        /// <param name="request">添加死亡信息的命令请求对象</param>
        /// <param name="cancellationToken">取消操作的取消标记</param>
        /// <returns>表示异步操作的任务，返回结果为包含整数结果的结果对象</returns>
        public async Task<Results<int>> Handle(EliminationAddCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = await _IeliminationModelService.Add(request.deathmodels);
                return Results<int>.DataResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }

    }
}
